import os
import configparser

class config:

    cf = configparser.ConfigParser()
    file = os.path.join(os.path.abspath("."),"config.ini")
    is_load = False
    @classmethod
    def load(cls):
        if not os.path.exists(cls.file):
            cls.init()
        with open(cls.file,encoding='utf-8') as fh:
            if fh.read(1) != '\ufeff':
                fh.seek(0)
            cls.cf.readfp(fh)

    @classmethod
    def save(cls):
        with open(cls.file,"w+") as fh:
            cls.cf.write(fh)

    @classmethod
    def get(cls,*arg,**kwags):
        if not cls.is_load:
            cls.load()
        return cls.cf.get(*arg,**kwags)

    @classmethod
    def getint(cls,*arg,**kwags):
        if not cls.is_load:
            cls.load()
        return cls.cf.getint(*arg,**kwags)

    @classmethod
    def init(cls):
        with open(cls.file,"a+",encoding="utf-8") as fh:
            fh.write(cls.default_config)

    default_config = ("[backend]\n"
              "url=http://127.0.0.1:5000\n"
              "runtime=5\n"
              "未分層=8229\n"
              "用心去维护（一）=8490\n"
              "用心去维护（二）=11340\n"
              "用心去维护（三）=8491\n"
              "用心去维护（四）=11341\n"
              "用心去维护（五）=8492\n"
              "用心去维护（六）=8494\n"
              "用心去维护（七）=8495\n"
              "每天观察（射龙门、幸运熊猫）=12668\n"
              "只有工商卡不返水（刷水）=8498\n"
              "黑名單=8502\n"
              "套利=8501\n"
              "試玩賬號=8503\n"
              "体育真钱推广=8500\n"
              "[招商银行安卓app]\n"
              "user_account=18620447891#用于记录出款错误\n"
              "classname=zsyhapp\n"
              "IMSI=+8618620447891\n"
              "pay_password=\n"
              "login_password=\n"
              "max=200000\n"
              "auto_stop=180000\n"
              "risk=50000\n"
              "level=8490\n"
              "[民生银行安卓app]\n"
              "classname=msyhapp\n"
              "user_account=#用于记录出款错误\n"
              "IMSI=+8618620447891\n"
              "pay_password=\n"
              "login_password=\n"
              "max=200000\n"
              "auto_stop=180000\n"
              "risk=50000\n"
              "level=8490\n"
              "[民生银行]\n"
              "classname=msyh\n"
              "user_account=#用于记录出款错误\n"
              "IMSI=+8618620447891\n"
              "pay_password=107032\n"
              "login_password=aa107032\n"
              "max=200000\n"
              "auto_stop=180000\n"
              "risk=50000\n"
              "level=8490,11340,8491\n"
              "mankind_login=0\n"
              "[招商银行]\n"
              "classname=zsyh\n"
              "user_account=#用于记录出款错误\n"
              "IMSI=+8618620447891\n"
              "pay_password=107032\n"
              "login_password=aa107032\n"
              "max=200000\n"
              "auto_stop=180000\n"
              "risk=50000\n"
              "level=8490,11340,8491\n"
              "mankind_login=0\n"
              )